<?php namespace App\Admin\Apply\Exchange\Criterias;

use App\Core\Repository\Criteria;
use App\Core\Repository\Repository;
use App\Admin\Client\Client\Repository as ClientRepository;

class CheckPermission extends Criteria{

    public function apply(Repository $repository){
        parent::apply($repository);
        $clientIds = [];
        $clients = with(new ClientRepository())->getMy();
        foreach($clients as $client){
            $clientIds[] = $client->id;
        }
        if(count($clientIds) > 0){
            $this->query->whereIn($this->formatField($this->model, 'client_id'), $clientIds);
        }else{//非法操作
            $this->query->whereRaw('1=0');
        }
    }
}